package com.example.config;

import com.example.templates.HotsTemplate;
import com.example.templates.PostsTemplate;
import com.jagregory.shiro.freemarker.ShiroTags;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;


/**
 * 定义模板标签之后，需要将这个模板标签配置到freemarker里面
 *
 * @Author 林必昭
 * @Date 2019/7/31 15:51
 */
@Configuration
public class FreemarkerConfig {

    @Autowired
    private freemarker.template.Configuration configuration;

    @Autowired
    private ApplicationContext applicationContext;

    @PostConstruct
    public void setUp() {
        configuration.setSharedVariable("posts", applicationContext.getBean(PostsTemplate.class));
        configuration.setSharedVariable("hots", applicationContext.getBean(HotsTemplate.class));

        // 前端需要shiro标签才能控制按钮的权限，用户的登陆状态，用户信息显示等
        configuration.setSharedVariable("shiro", new ShiroTags());
    }

}
